﻿
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Labthink.PCSoft.UniversalHost4.UserControls.CustomControls
{
    /// <summary>
    /// 按照步骤 1a 或 1b 操作，然后执行步骤 2 以在 XAML 文件中使用此自定义控件。
    ///
    /// 步骤 1a) 在当前项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
    /// 元素中: 
    ///
    ///     xmlns:MyNamespace="clr-namespace:Labthink.PCSoft.UniversalHost4.UserControls.CustomControls"
    ///
    ///
    /// 步骤 1b) 在其他项目中存在的 XAML 文件中使用该自定义控件。
    /// 将此 XmlNamespace 特性添加到要使用该特性的标记文件的根 
    /// 元素中: 
    ///
    ///     xmlns:MyNamespace="clr-namespace:Labthink.PCSoft.UniversalHost4.UserControls.CustomControls;assembly=Labthink.PCSoft.UniversalHost4.UserControls.CustomControls"
    ///
    /// 您还需要添加一个从 XAML 文件所在的项目到此项目的项目引用，
    /// 并重新生成以避免编译错误: 
    ///
    ///     在解决方案资源管理器中右击目标项目，然后依次单击
    ///     “添加引用”->“项目”->[浏览查找并选择此项目]
    ///
    ///
    /// 步骤 2)
    /// 继续操作并在 XAML 文件中使用控件。
    ///
    ///     <MyNamespace:IconButton/>
    ///
    /// </summary>
    public class IconButton : Button
    {
        public static readonly DependencyProperty FIconProperty =
            DependencyProperty.Register("FIcon", typeof(string), typeof(IconButton), new PropertyMetadata("\ue604"));
        /// <summary>
        /// 按钮字体图标编码
        /// </summary>
        public string FIcon
        {
            get => (string)GetValue(FIconProperty);
            set => SetValue(FIconProperty, value);
        }

        public static readonly DependencyProperty FIconSizeProperty =
            DependencyProperty.Register("FIconSize", typeof(double), typeof(IconButton), new PropertyMetadata(20.0));
        /// <summary>
        /// 按钮字体图标大小
        /// </summary>
        public double FIconSize
        {
            get => (double)GetValue(FIconSizeProperty);
            set => SetValue(FIconSizeProperty, value);
        }

        public static readonly DependencyProperty FIconMarginProperty = DependencyProperty.Register(
            "FIconMargin", typeof(Thickness), typeof(IconButton), new PropertyMetadata(new Thickness(0, 1, 3, 1)));
        /// <summary>
        /// 字体图标间距
        /// </summary>
        public Thickness FIconMargin
        {
            get => (Thickness)GetValue(FIconMarginProperty);
            set => SetValue(FIconMarginProperty, value);
        }

        public Brush FIconForeground
        {
            get => (Brush)GetValue(FIconForegroundProperty);
            set => SetValue(FIconForegroundProperty, value);
        }

        public static readonly DependencyProperty FIconForegroundProperty =
            DependencyProperty.Register("FIconForeground", typeof(Brush), typeof(IconButton), new PropertyMetadata(Brushes.White));

        public static readonly DependencyProperty CornerRadiusProperty =
            DependencyProperty.Register("CornerRadius", typeof(CornerRadius), typeof(IconButton), new PropertyMetadata(new CornerRadius(2)));
        /// <summary>
        /// 按钮圆角大小,左上，右上，右下，左下
        /// </summary>
        public CornerRadius CornerRadius
        {
            get => (CornerRadius)GetValue(CornerRadiusProperty);
            set => SetValue(CornerRadiusProperty, value);
        }

        public static readonly DependencyProperty ContentDecorationsProperty = DependencyProperty.Register(
            "ContentDecorations", typeof(TextDecorationCollection), typeof(IconButton), new PropertyMetadata(null));
        public TextDecorationCollection ContentDecorations
        {
            get => (TextDecorationCollection)GetValue(ContentDecorationsProperty);
            set => SetValue(ContentDecorationsProperty, value);
        }

        static IconButton()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(IconButton), new FrameworkPropertyMetadata(typeof(IconButton)));
        }
    }
}
